package com.clkj.cldisabledmanclient.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.clkj.cldisabledmanclient.R;

import java.util.List;

/**
 * 积分列表adapter
 * Created by Administrator on 2016/7/25.
 */
public class ListAdapterForYear extends BaseAdapter {

    List<String> stateList;
    Context mContext;
    LayoutInflater mLayoutInflater;
    private int defItem;//声明默认选中的项

    public ListAdapterForYear(List<String> stateList, Context mContext) {
        this.stateList = stateList;
        this.mContext = mContext;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return stateList.size();
    }

    @Override
    public Object getItem(int position) {
        return stateList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setDefSelect(int position) {
        this.defItem = position;
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;

        if (convertView == null) {
            convertView = mLayoutInflater.inflate(R.layout.item_year, null);
            viewHolder = new ViewHolder();
            viewHolder.mTvState = (TextView) convertView.findViewById(R.id.tv_year);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        if (defItem == position) {
            convertView.setBackgroundColor(mContext.getResources().getColor(R.color.white));
        } else {
            convertView.setBackgroundColor(mContext.getResources().getColor(R.color.graylight));
        }
        String state = stateList.get(position);

        viewHolder.mTvState.setText(state);
        return convertView;
    }


    static class ViewHolder {
        private TextView mTvState;

    }
}
